package com.eidos.blogs.openapi.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author ：Eidos
 * @date ：Created in 2020/12/15
 * @description：swagger配置
 * @modified By：
 * @version: 1.0
 */
@Configuration
@EnableSwagger2
public class SpringFoxConfig {


    //配置swagger信息=apiInfo
    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档") //设置文档的标题
                .description("接口介绍") // 设置文档的描述
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())
//                .enable(false)  //配置是否启用swagger  false关闭
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }


}
